*****Preparation 
***Set scheme for figures
set scheme plotplain

***Creating relevant variables for use in analyses
**Different versions of the treatment variable (message)
recode message (1=1) (3=1) (2=2) (4=2) (5=5), gen(message_neutralvsmoral)
label define message_neutralvsmoral 1"Neutral" 2"Moral" 5"Control"
label values message_neutralvsmoral message_neutralvsmoral

recode message (1=1) (2=1) (3=2) (4=2) (5=0), gen(argtype)
label define argtype 1"economy" 2"culture" 0"control"
label values argtype argtype

**Moral conviction: higher values = more morally convicted
alpha q13 q14
gen moral_conviction_index = ((q13+q14)-2)/8

**Attitude extremity: higher values = more extreme immigration attitude (postive or negative)
gen im_extreme = 0 if q12==4
replace im_extreme = 1 if q12==3 | q12==5
replace im_extreme = 2 if q12==2 | q12==6
replace im_extreme = 3 if q12==1 | q12==7

**Social distance - correlation and factor analyses as preparation for constructing indices
*Appendix 1, Table A1.6.
corr distance_primemin distance_mayor distance_neighbour distance_colleague distance_family distance_spouse distance_friend distance_shopowner distance_teacher

*Appendix 1, Tables A1.7., A1.8.
factor distance_primemin distance_mayor distance_neighbour distance_colleague distance_family distance_spouse distance_friend distance_shopowner distance_teacher
rotate

**Social distance political leaders
*First, rescale so higher values = more distance (less happy with person having different opinion)
recode distance_primemin (1=5) (2=4) (3=3) (4=2) (5=1)
recode distance_mayor (1=5) (2=4) (3=3) (4=2) (5=1)
alpha distance_primemin distance_mayor
*Generate index
gen distance_polleader = ((distance_primemin + distance_mayor)-2)/8

**Social distance social interaction partners
*First, rescale so higher values = more distance (less happy with person having different opinion)
recode distance_neighbour (1=5) (2=4) (3=3) (4=2) (5=1)
recode distance_colleague (1=5) (2=4) (3=3) (4=2) (5=1)
recode distance_family (1=5) (2=4) (3=3) (4=2) (5=1)
recode distance_spouse (1=5) (2=4) (3=3) (4=2) (5=1)
recode distance_friend (1=5) (2=4) (3=3) (4=2) (5=1)
recode distance_shopowner (1=5) (2=4) (3=3) (4=2) (5=1)
recode distance_teacher (1=5) (2=4) (3=3) (4=2) (5=1)
alpha distance_neighbour distance_colleague distance_family distance_spouse distance_friend distance_shopowner distance_teacher
*Generate index
gen distance_personalrelations = ((distance_neighbour + distance_colleague + distance_family + distance_spouse + distance_friend + distance_shopowner + distance_teacher)-7)/28

**Party identification (five groups)
gen party_id = 1 if q6==1
replace party_id = 2 if q6==11
replace party_id = 3 if q6==2 | q6==6 | q6==12 | q6==13
replace party_id = 4 if q6==3 | q6==4 | q6==5 | q6==7 | q6==8 | q6==9 | q6==10 
recode party_id (1=1) (2=2) (3=3) (4=4) (else=0)
label define partyid 0"No party" 1"Socialdemokratiet" 2"Venstre" 3"Other left-wing" 4"Other right-wing"
label values party_id partyid

**Manipulation check status
gen mani_check = .
replace mani_check = 1 if q17==1 & q18==1 & partysponsor==1 
replace mani_check = 2 if q17==1 & q18==11 & partysponsor==2
recode mani_check (1=1) (2=1) (else=2)
replace mani_check = 3 if message==5
label define manipulation 1"passed" 2"not passed" 3"control"
label values mani_check manipulation

recode mani_check (1=1) (2=2) (3=1), gen(mani_check2)
label values mani_check2 manipulation

*****Analysis Part I: Direct effects of message exposure on the four outcomes
***Figure 1 (DK results), Note: Regression output produced in the below analyses is found in Appendix 2, Table A2.1. Coefficient plots are found in Figure 1
reg moral_conviction_index ib5.message i.mani_check2
coefplot, drop(_cons 2.mani_check2) levels (95 90) xline(0) xscale(range(-.1 .15))

reg im_extreme ib5.message i.mani_check2
coefplot, drop(_cons 2.mani_check2) levels (95 90) xline(0) xscale(range(-.3 .3))

reg distance_polleader ib5.message i.mani_check2
coefplot, drop(_cons 2.mani_check2) levels (95 90) xline(0) xscale(range(-.05 .1))

reg distance_personalrelations ib5.message i.mani_check2
coefplot, drop(_cons 2.mani_check2) levels (95 90) xline(0) xscale(range(-.05 .1))

***Appendix 2 comparison plots
**Figure A2.2.
reg moral_conviction_index ib5.message i.mani_check2
margins i.message, pwcompare(effects)
marginsplot, horizontal unique recast(scatter) yscale(reverse) xline(0) xscale(range(-.15 .15)) 

**Figure A2.4.
reg im_extreme ib5.message i.mani_check2
margins i.message, pwcompare(effects)
marginsplot, horizontal unique recast(scatter) yscale(reverse) xline(0) xscale(range(-.4 .4))

**Figure A2.6.
reg distance_polleader ib5.message i.mani_check2
margins i.message, pwcompare(effects)
marginsplot, horizontal unique recast(scatter) yscale(reverse) xline(0) xscale(range(-.15 .15)) 

**Figure A2.8.
reg distance_personalrelations ib5.message i.mani_check2
margins i.message, pwcompare(effects)
marginsplot, horizontal unique recast(scatter) yscale(reverse) xline(0) xscale(range(-.15 .15)) 

***Appendix 4. Mediation analysis
*Recoding the treatment variable so the control condition has the value of "0"
recode message (1=1) (2=2) (3=3) (4=4) (5=0), gen(message0)
label values message0 message

**Mediation analyses as basis for matrices for creating Figure A4.2., Distance political leaders
*Economy
medeff (regress moral_conviction_index message0 mani_check2) (regress distance_polleader moral_conviction_index message0 mani_check2) if message0==0 | message0==1, mediate(moral_conviction_index) treat(message0 0 1) sims(1000) seed(20)

matrix distancepol_eco = (.0270573,.0038156 \ -.0193029,-.0034847 \ .0751289,.012688)
matrix colnames distancepol_eco = totaleff acme
matrix rownames distancepol_eco = mean lb95 ub95
matrix list distancepol_eco 

*Economy-moral
medeff (regress moral_conviction_index message0 mani_check2) (regress distance_polleader moral_conviction_index message0 mani_check2) if message0==0 | message0==2, mediate(moral_conviction_index) treat(message0 0 2) sims(1000) seed(20)

matrix distancepol_moraleco = (.0240689,.0108046 \ -.0232805,-.0005928 \ .072496,.0242618)
matrix colnames distancepol_moraleco = totaleff acme
matrix rownames distancepol_moraleco = mean lb95 ub95
matrix list distancepol_moraleco 

*Culture
medeff (regress moral_conviction_index message0 mani_check2) (regress distance_polleader moral_conviction_index message0 mani_check2) if message0==0 | message0==3, mediate(moral_conviction_index) treat(message0 0 3) sims(1000) seed(20)

matrix distancepol_cul = (.0492777,.0076771 \ .0018087,-.0028079 \ .0971187,.0199423)
matrix colnames distancepol_cul = totaleff acme
matrix rownames distancepol_cul = mean lb95 ub95
matrix list distancepol_cul 

*Culture-moral
medeff (regress moral_conviction_index message0 mani_check2) (regress distance_polleader moral_conviction_index message0 mani_check2) if message0==0 | message0==4, mediate(moral_conviction_index) treat(message0 0 4) sims(1000) seed(20)

matrix distancepol_moralcul = (.0419996,.0157367 \ -.0052562,.0035315 \ .0905396,.0300833)
matrix colnames distancepol_moralcul = totaleff acme
matrix rownames distancepol_moralcul = mean lb95 ub95
matrix list distancepol_moralcul

*Figure A4.2. based on above mediation analysis output
coefplot (matrix(distancepol_eco), ci((2 3))) (matrix(distancepol_moraleco), ci((2 3))) (matrix(distancepol_cul), ci((2 3))) (matrix(distancepol_moralcul), ci((2 3))), xline(0) xscale(range(-.1 .1))

**Mediation analyses as basis for matrices for creating Figure A4.4., Distance social interaction partners
*Economy
medeff (regress moral_conviction_index message0 mani_check2) (regress distance_personalrelations moral_conviction_index message0 mani_check2) if message0==0 | message0==1, mediate(moral_conviction_index) treat(message0 0 1) sims(1000) seed(20)

matrix distancepers_eco = (-.0016432,.0030395 \ -.0433424,-.0064138 \ .0407715,.0133049)
matrix colnames distancepers_eco = totaleff acme
matrix rownames distancepers_eco = mean lb95 ub95
matrix list distancepers_eco 

*Economy-moral
medeff (regress moral_conviction_index message0 mani_check2) (regress distance_personalrelations moral_conviction_index message0 mani_check2) if message0==0 | message0==2, mediate(moral_conviction_index) treat(message0 0 2) sims(1000) seed(20)

matrix distancepers_moraleco = (.0146116,.0114601 \ -.0281935,.0006608 \ .0587487,.0242097)
matrix colnames distancepers_moraleco = totaleff acme
matrix rownames distancepers_moraleco = mean lb95 ub95
matrix list distancepers_moraleco 

*Culture
medeff (regress moral_conviction_index message0 mani_check2) (regress distance_personalrelations moral_conviction_index message0 mani_check2) if message0==0 | message0==3, mediate(moral_conviction_index) treat(message0 0 3) sims(1000) seed(20)

matrix distancepers_cul = (.0457223,.0069252 \ .0025415,-.0035273 \ .0895678,.0190141)
matrix colnames distancepers_cul = totaleff acme
matrix rownames distancepers_cul = mean lb95 ub95
matrix list distancepers_cul 

*Culture-moral
medeff (regress moral_conviction_index message0 mani_check2) (regress distance_personalrelations moral_conviction_index message0 mani_check2) if message0==0 | message0==4, mediate(moral_conviction_index) treat(message0 0 4) sims(1000) seed(20)

matrix distancepers_moralcul = (.0244315,.0161133 \ -.0196154,.0030102 \ .0695611,.031151)
matrix colnames distancepers_moralcul = totaleff acme
matrix rownames distancepers_moralcul = mean lb95 ub95
matrix list distancepers_moralcul

*Figure A4.4. based on above mediation analysis output
coefplot (matrix(distancepers_eco), ci((2 3))) (matrix(distancepers_moraleco), ci((2 3))) (matrix(distancepers_cul), ci((2 3))) (matrix(distancepers_moralcul), ci((2 3))), xline(0) xscale(range(-.1 .1))

*****Analysis Part II: Party identity moderation
***Is there a direct effect or two-way interaction effect of party sponsor on moral conviction? No
reg moral_conviction_index i.message i.partysponsor i.party_id i.argtype i.mani_check2
reg moral_conviction_index i.message_neutralvsmoral i.partysponsor i.argtype i.mani_check2 
reg moral_conviction_index i.message##i.partysponsor i.party_id i.argtype i.mani_check2
reg moral_conviction_index i.message_neutralvsmoral##i.partysponsor i.argtype i.mani_check2

***Producing Figure 2
reg moral_conviction_index i.mani_check2 i.argtype ib2.partysponsor##i.party_id if message_neutralvsmoral==2
margins, dydx(partysponsor) over(party_id) post
est store moralmes

reg moral_conviction_index i.mani_check2 i.argtype ib2.partysponsor##i.party_id if message_neutralvsmoral==1
margins, dydx(partysponsor) over(party_id) post
est store neutralmes

coefplot neutralmes moralmes, drop(_cons) xline(0) levels(95 90)

***Appendix 5. Partisan effects
**Figure A5.1.
reg im_extreme i.mani_check2 i.argtype ib2.partysponsor##i.party_id if message_neutralvsmoral==2
margins, dydx(partysponsor) over(party_id) post
est store moralmesex

reg im_extreme i.mani_check2 i.argtype ib2.partysponsor##i.party_id if message_neutralvsmoral==1
margins, dydx(partysponsor) over(party_id) post
est store neutralmesex

coefplot neutralmesex moralmesex, drop(_cons) xline(0) levels(95 90)

**Figure A5.2.
reg distance_polleader i.mani_check2 i.argtype ib2.partysponsor##i.party_id if message_neutralvsmoral==2
margins, dydx(partysponsor) over(party_id) post
est store moralmespol

reg distance_polleader i.mani_check2 i.argtype ib2.partysponsor##i.party_id if message_neutralvsmoral==1
margins, dydx(partysponsor) over(party_id) post
est store neutralmespol

coefplot neutralmespol moralmespol, drop(_cons) xline(0) levels(95 90)

**Figure A5.3.
reg distance_personalrelations i.mani_check2 i.argtype ib2.partysponsor##i.party_id if message_neutralvsmoral==2
margins, dydx(partysponsor) over(party_id) post
est store moralmespers

reg distance_personalrelations i.mani_check2 i.argtype ib2.partysponsor##i.party_id if message_neutralvsmoral==1
margins, dydx(partysponsor) over(party_id) post
est store neutralmespers

coefplot neutralmespers moralmespers, drop(_cons) xline(0) levels(95 90)